package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.Share;
import com.zygh.interactiveplatform.module.entity.Share;
import com.zygh.interactiveplatform.module.service.ShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-02-02
 */
@RestController
@RequestMapping("/share")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_SHARE})
public class ShareController {
    @Resource
    private ShareService shareService;

    @ApiOperation(value = "数据共享管理新增", notes = "数据共享管理新增")
    @PostMapping("addSharee")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_SHARE, content = "数据共享管理新增")
    public ResponseDTO addSharee(@RequestBody @Valid Share share) {
        return shareService.addShare(share);
    }

    @ApiOperation(value = "数据共享管理修改", notes = "数据共享管理修改")
    @PostMapping("updateShare")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_SHARE, content = "数据共享管理修改")
    public ResponseDTO updateShare(@RequestBody @Valid Share share) {
        return shareService.updateShare(share);
    }

    @ApiOperation(value = "数据共享管理删除", notes = "数据共享管理删除")
    @PostMapping("deleteShare")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_SHARE, content = "数据共享管理删除")
    public ResponseDTO deleteShare(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return shareService.deleteShare(new_id);
    }

    @ApiOperation(value = "查询所有数据共享管理", notes = "查询所有数据共享管理")
    @GetMapping("findShareAll")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_SHARE, content = "查询所有数据共享管理")
    public ResponseDTO findShareAll(Integer current, Integer size) {
        return shareService.findShareAll(current, size);
    }
}
